//
//  YXYWallLikeTableViewCell.m
//  Topit
//
//  Created by dllo on 15/12/9.
//  Copyright © 2015年 YXY. All rights reserved.
//

#import "YXYWallLikeTableViewCell.h"
#import "YXYWallLikeLowerCollectionViewCell.h"
@implementation YXYWallLikeTableViewCell
- (void)dealloc {
    [_array release];
    [_flowLayout release];
    [_collectionView release];
    [_label release];
    [_array release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.number = [NSMutableArray arrayWithCapacity:0];
        self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_flowLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        [_collectionView registerClass:[YXYWallLikeLowerCollectionViewCell class] forCellWithReuseIdentifier:@"YXYWallLikeLowerCollectionViewCellIdentifier"];
        
        [self addSubview:_collectionView];
        [_collectionView release];

        self.label = [[UILabel alloc] initWithFrame:CGRectZero];
        _label.font = [UIFont systemFontOfSize:10];
        _label.textColor = [UIColor grayColor];
        [self addSubview:_label];
        [_label release];

    }
    return self;
}

-(void)setArray:(NSMutableArray *)array {
    if (_array != array) {
        [_array release];
        _array = [array retain];
    }

    YXYWallPaperModel *wallPaperModel = [array firstObject];
    [_number addObjectsFromArray:wallPaperModel.itemArray];

    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _label.frame = CGRectMake(5, 2, self.width, 10);
    _flowLayout.itemSize = CGSizeMake(self.width / 4.1, self.height - 20);
    _flowLayout.minimumInteritemSpacing = 0;
    _flowLayout.minimumLineSpacing = 0;
    _flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collectionView.frame = CGRectMake(0, 0, self.width, self.height - 10);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _number.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YXYWallLikeLowerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YXYWallLikeLowerCollectionViewCellIdentifier" forIndexPath:indexPath];

    YXYWallItemModel *wallItemModel = _number[indexPath.item];
//    NSLog(@"%@", wallItemModel.name);
    [cell setWallItemModel:wallItemModel];
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
